package com.starleague.battletech.hexagonal.jpa.appengine;

import java.util.Map;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;

import com.starleague.battletech.hexagonal.BattletechHexTerrainType;
import com.starleague.battletech.hexagonal.IBattletechHexTerrain;
import com.starleague.jpa.appengine.GaeDao;

@Entity(name = "BATTLETECH_HEX_TERRAIN")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class BattletechHexTerrainGae
        extends GaeDao
        implements IBattletechHexTerrain
{
    // Remember, AppEngine doesn't support FetchType.EAGER / Joins
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private BattletechHexGae hex;

    @Basic(optional = false)
    @Column(nullable = false)
    @Enumerated(EnumType.STRING)
    private BattletechHexTerrainType hexTerrainType;

    @Basic(optional = false)
    @Column(nullable = false)
    private int level;

    BattletechHexTerrainGae(BattletechHexGae hex,
                            BattletechHexTerrainType hexTerrainType,
                            int level)
    {
        this.hex = hex;
        this.hexTerrainType = hexTerrainType;
        this.level = level;
    }

    protected BattletechHexTerrainGae()
    {
        //
    }

    @Override
    public BattletechHexGae getHex()
    {
        return this.hex;
    }

    @Override
    public BattletechHexTerrainType getHexTerrainType()
    {
        return this.hexTerrainType;
    }

    @Override
    public int getLevel()
    {
        return this.level;
    }

    @Override
    public Map<String, Object> infoProperties()
    {
        Map<String, Object> infoPropertyMap = super.infoProperties();
        infoPropertyMap.put("terrainType", this.hexTerrainType);
        infoPropertyMap.put("level", this.level);
        return infoPropertyMap;
    }
}
